//
//  JWSafeCtry.m
//  test
//
//  Created by 李彦宏 on 2018/1/23.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "JWSafeCtry.h"
#import "UpdatePwdVC.h"
#import "JWUserManager.h"
#import "JWUserModel.h"
#import "LoginViewController.h"
@interface JWSafeCtry ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation JWSafeCtry
//UItableView初始化
- (void)setupTable
{
    UITableView *tableView=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    //隐藏组距导航栏的间距
    tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    tableView.backgroundColor=[UIColor whiteColor];
    tableView.showsHorizontalScrollIndicator=NO;
    tableView.showsVerticalScrollIndicator=NO;
    tableView.dataSource=self;
    tableView.delegate=self;
    tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:tableView];
    self.tableView=tableView;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"账号安全";
    [self setupTable];
    // Do any additional setup after loading the view.
}
#pragma -mark -----------------------------tableview datasource and delegate---------------------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 1.创建cell
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }
    if(indexPath.row==0){
        cell.textLabel.text=@"修改密码：";
        cell.imageView.image=[UIImage imageNamed:@"person-safe-icon1"];
    }else{
        cell.textLabel.text=@"退出登录";
        cell.imageView.image=[UIImage imageNamed:@"退出"];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if(indexPath.row==0){
        UpdatePwdVC *vc = [[UpdatePwdVC alloc]init];
        vc.type = @"3";
        [self.navigationController pushViewController:vc animated:YES];
        
    }else{
        
        UIAlertController *alertview=[UIAlertController alertControllerWithTitle:@"确定退出登录？" message:nil preferredStyle:UIAlertControllerStyleAlert];

        // 设置按钮
        UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *defult = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 
            LoginViewController *vc = [[LoginViewController alloc]init];
            [vc wr_setNavBarBackgroundAlpha:0];
            [self presentViewController:vc animated:YES completion:nil];
           
            [JWUserManager loginOut];
            [self.tableView reloadData];
        }];

        [alertview addAction:cancel];
        [alertview addAction:defult];

        [self presentViewController:alertview animated:YES completion:nil];
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
